package org.ym.system.ui.api;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.ym.basic.base.ApiResult;
import org.ym.database.hibernate.query.QueryFilter;
import org.ym.system.application.commandservice.SysUserCommandService;
import org.ym.system.application.queryservice.SysUserQueryService;
import org.ym.system.ui.vo.SysUserVO;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author ym
 */
@Controller
@RequestMapping("/sysUser")
public class SysUserController {
    @Resource
    SysUserCommandService sysUserCommandService;
    @Resource
    SysUserQueryService sysUserQueryService;

    /**
     * 分页查询数据
     * @param request 请求
     * @return 数据
     */
    @PostMapping("/page")
    public ApiResult page(HttpServletRequest request){
        QueryFilter queryFilter = new QueryFilter();
        return ApiResult.ok(sysUserQueryService.page(queryFilter));
    }

    /**
     * 根据逻辑主键获取数据
     * @param id 逻辑主键
     * @return 数据
     */
    @PostMapping("/get")
    public ApiResult get(Long id){
        return ApiResult.ok(sysUserQueryService.get(id));
    }

    /**
     * 保存
     * @param sysUserVO VO
     * @return 保存后对象
     */
    @PostMapping("/save")
    public ApiResult save(@RequestBody SysUserVO sysUserVO){
        return ApiResult.ok(sysUserCommandService.save(sysUserVO.toCommand()));
    }
}
